<?php
/**
 * Basic User Permission Map
 * Uses arrays in memory to map permissions to rolls
 * may be extended to be less manual
 * 
 * 
 * @author Alton Crossley <crossleyframework@nogahidebootstrap.com>
 * @package Crossley Framework
 *  
 * @copyright Copyright (c) 2003-2009, Nogaide BootStrap INC. All rights reserved.
 * @license BSD http://opensource.org/licenses/bsd-license.php
 * @version $Id:$
 * 
 */
class X_User_Permission_Map implements X_User_Permission_Map_Interface
{
    /**
     * internal map store
     * 
     * @var array
     */
    protected $_aMap = array();
    
	/**
     * @param unknown_type $sRoll
     * @param unknown_type $sPermissionKey
     * @param unknown_type $sDetail
     */
    public function createMap($sRoll, $sPermissionKey, $sDetail = Null)
    {
        $this->_aMap[$this->_buildPermKey($sPermissionKey, $sDetail)] = $sRoll;
    }

	/**
     * @param unknown_type $sPermissionKey
     * @param unknown_type $sDetail
     */
    public function map($sPermissionKey, $sDetail = Null)
    {
        $sKey = $this->_buildPermKey($sPermissionKey, $sDetail);
        if (array_key_exists($sKey, $this->_aMap))
        {
            return $this->_aMap[$sKey];
        }
        return false;
    }
    
	/**
     * combined like detail_subject
     * 
     * @param string $sPermissionKey
     * @param string $sDetail
     * @return string
     */
    protected function _buildPermKey($sPermissionKey, $sDetail)
    {
        return X_String::toCode($sDetail . ' ' . $sSubjectUri, true);
    }
    
} 